package com.carrent.bus.service.impl;

import com.carrent.bus.domain.Customer;
import com.carrent.bus.mapper.CustomerMapper;
import com.carrent.bus.service.CustomerService;
import com.carrent.bus.vo.CustomerVo;
import com.carrent.sys.utils.DataGridView;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *
 */
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    //根据身份证查询
    @Override
    public Customer queryCustomerByIdentity(String identity) {
        return customerMapper.selectByPrimaryKey(identity);
    }
    //查询所有客户
    @Override
    public DataGridView loadAllCustomer(CustomerVo customerVo) {
        Page<Object> page = PageHelper.startPage(customerVo.getPage(),customerVo.getLimit());
        List<Customer> data = customerMapper.queryAllCustomer(customerVo);
        return new DataGridView(page.getTotal(),data);
    }
    //添加客户
    @Override
    public void addCustomer(CustomerVo customerVo) {
        //设置客户录入时间
       customerVo.setCreatetime(new Date());
       customerMapper.insertSelective(customerVo);
    }
    //修改
    @Override
    public void updateCustomer(CustomerVo customerVo) {
        customerMapper.updateByPrimaryKeySelective(customerVo);
    }
    //删除
    @Override
    public void deleteCustomer(String identity) {
        customerMapper.deleteByPrimaryKey(identity);
    }
    //批量删除
    @Override
    public void deleteBatchCustomer(String[] ids) {
        for (String id:ids) {
            customerMapper.deleteByPrimaryKey(id);
        }
    }
}
